import random
import time as tt
from urllib.parse import urlparse

from application.db.mysql_db.nsfc.NsfcInfoList import NsfcInfoList
from application.db.mysql_db.nsfc.NsfcInfoSectionList import NsfcInfoSectionList
from application.db.mysql_db.test.demo1 import A
from application.db.mysql_db.test.demo2 import B
from application.etl.write.base_batch_observer import BaseBatchObserver
from application.db import get_database_connection

class Test(BaseBatchObserver):
    """
    资源信息批量观察者类，负责处理资源信息数据并写入数据库
    """

    def process_batch(self, batch_data):
        """
        批量处理并写入数据库
        """
        print(f"\n[ResourceBatchObserver] 批量处理 {len(batch_data)} 行数据:")
        print("=" * 50)
        data=[]
        for item in batch_data:
            data.append({
                "id": item['id'],
                "a_name": item['title_level'],
            })
        A.insert_many(data).execute()

class Test2(BaseBatchObserver):
    """
    资源信息批量观察者类，负责处理资源信息数据并写入数据库
    """

    def process_batch(self, batch_data):
        """
        批量处理并写入数据库
        """
        print(f"\n[ResourceBatchObserver] 批量处理 {len(batch_data)} 行数据:")
        print("=" * 50)
        0/0
        data=[]
        for item in batch_data:
            data.append({
                "id": item['id'],
                "b_name": item['section_attr'],
            })
        B.insert_many(data).execute()